#include "route.hpp"
#include <cassert>
#include <iostream>
#include <numeric>
#include <vector>
Route::Route(std::vector<Track *> tracks, std::vector<DIRECTION> directions,
             int tracksNum) {
    assert(tracksNum == tracks.size());
    assert(tracksNum == directions.size());
    for (int i = 0; i < tracksNum; i++) {
        this->items.push_back(RouteItem(tracks[i], directions[i]));
    }
    this->distance = 0.0;
    this->headIndex = 0;
    this->tailIndex = 0;
    this->headPosition = 0.0;
    this->tailPosition = 0.0;
    this->tracksNum = tracksNum;
    return;
}

Route::~Route() {}

fp_type Route::getDistanceToTerminal(){
    fp_type distance = 0.0;
    for(int i = this->headIndex; i < this->tracksNum; i++){
        distance += this->items[i].track->getLength();
    }
    distance -= this->headPosition; // 减去车头在车头区间中已经走过的长度。
    return distance;
}
